package com.example.springboot.controller;

import com.example.springboot.entity.announcements;
import com.example.springboot.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin(origins = "http://localhost:7070")
@RestController
@RequestMapping("/api/announcement")
public class AnnouncementController {

    @Autowired
    private AnnouncementService announcementService;

    @GetMapping("/all")
    public List<announcements> getAllAnnouncements() {
        return announcementService.getAllAnnouncements();
    }

    @GetMapping("/{id}")
    public announcements getAnnouncementById(@PathVariable("id") int announcementId) {
        return announcementService.getAnnouncementById(announcementId);
    }

    @PostMapping("/add")
    public void addAnnouncement(@RequestBody announcements announcement) {
        announcementService.addAnnouncement(announcement);
    }

    @PutMapping("/update")
    public void updateAnnouncement(@RequestBody announcements announcement) {
        announcementService.updateAnnouncement(announcement);
    }

    @DeleteMapping("/delete/{id}")
    public void deleteAnnouncement(@PathVariable("id") int announcementId) {
        announcementService.deleteAnnouncement(announcementId);
    }
}
